<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><div id="myscoll"></div><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Vue3+TS项目开发小技巧 | 晚夜微雨问海棠のBlog</title><meta name="keywords" content="Vue3+TS项目开发小技巧"><meta name="author" content="晚夜微雨问海棠"><meta name="copyright" content="晚夜微雨问海棠"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="defineProps（父组件向子组件传值） 父组件向子组件传递数据，子组件使用defineProps，来接收  父组件   1234567891011121314151617181920212223242526272829&lt;template&gt;	&lt;!-- 登录 --&gt;	&lt;div class&#x3D;&quot;container mt-5&quot; style&#x3D;&quot;">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue3+TS项目开发小技巧">
<meta property="og:url" content="http://example.com/posts/5d3e0e97.html">
<meta property="og:site_name" content="晚夜微雨问海棠のBlog">
<meta property="og:description" content="defineProps（父组件向子组件传值） 父组件向子组件传递数据，子组件使用defineProps，来接收  父组件   1234567891011121314151617181920212223242526272829&lt;template&gt;	&lt;!-- 登录 --&gt;	&lt;div class&#x3D;&quot;container mt-5&quot; style&#x3D;&quot;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg">
<meta property="article:published_time" content="2023-06-14T10:12:11.000Z">
<meta property="article:modified_time" content="2023-06-24T02:56:59.811Z">
<meta property="article:author" content="晚夜微雨问海棠">
<meta property="article:tag" content="朝花夕拾">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/posts/5d3e0e97"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="manifest" href="/manifest.json"/><meta name="msapplication-TileColor" content="#49b1f5"/><link rel="apple-touch-icon" sizes="180x180" href="/img/siteicon/128.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/siteicon/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/siteicon/16.png"/><link rel="mask-icon" href="/img/siteicon/128.png" color="#5bbad5"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":150},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":650,"languages":{"author":"作者: 晚夜微雨问海棠","link":"链接: ","source":"来源: 晚夜微雨问海棠のBlog","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Vue3+TS项目开发小技巧',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-24 10:56:59'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"> <link rel="stylesheet" href="/swiper/swiper.min.css"> <link rel="stylesheet" href="/swiper/swiperstyle.css"> <link rel="stylesheet" href="/css/rightMenu.css"> <link rel="stylesheet" href="/css/constrain.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-categories-card@1.0.0/lib/categorybar.css"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-blog@2.0.3/css/runtime/runtime.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiperstyle.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/atom.xml" title="晚夜微雨问海棠のBlog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg" style="background:https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg;background-attachment: local;background-position: center;background-size: cover;background-repeat: no-repeat;"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://img2.woyaogexing.com/2022/06/28/de1ce3dc65468fd4!400x400.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">31</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">17</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bangumis/index.html"><i class="fa-fw fas fa-home"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活馆</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://81.69.189.243:8082/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">晚夜微雨问海棠のBlog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bangumis/index.html"><i class="fa-fw fas fa-home"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活馆</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://81.69.189.243:8082/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Vue3+TS项目开发小技巧</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-06-14T10:12:11.000Z" title="发表于 2023-06-14 18:12:11">2023-06-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-06-24T02:56:59.811Z" title="更新于 2023-06-24 10:56:59">2023-06-24</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">5.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>18分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Vue3+TS项目开发小技巧"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="defineProps（父组件向子组件传值）"><a href="#defineProps（父组件向子组件传值）" class="headerlink" title="defineProps（父组件向子组件传值）"></a>defineProps（父组件向子组件传值）</h1><ol>
<li><p>父组件向子组件传递数据，子组件使用defineProps，来接收</p>
</li>
<li><p>父组件</p>
</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;!-- 登录 --&gt;</span><br><span class="line">	&lt;div class=&quot;container mt-5&quot; style=&quot;max-width: 800px&quot;&gt;</span><br><span class="line">		&lt;div&gt;</span><br><span class="line">			&lt;div class=&quot;mb-3&quot;&gt;</span><br><span class="line">				&lt;label for=&quot;exampleInputEmail1&quot; class=&quot;form-label&quot;&gt;Email address&lt;/label&gt;</span><br><span class="line">				&lt;ValidationInput :rules=&quot;emailRule&quot;&gt;&lt;/ValidationInput&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line">		&lt;/div&gt;</span><br><span class="line">	&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup lang=&quot;ts&quot;&gt;</span><br><span class="line">import ValidationInput, &#123; RuleProps &#125; from &#x27;../components/ValidationInput.vue&#x27;</span><br><span class="line"></span><br><span class="line">const emailRule: RuleProps[] = [</span><br><span class="line">	&#123;</span><br><span class="line">		type: &#x27;require&#x27;,</span><br><span class="line">		desc: &#x27;邮箱地址不能为空!&#x27;</span><br><span class="line">	&#125;,</span><br><span class="line">	&#123;</span><br><span class="line">		type: &#x27;email&#x27;,</span><br><span class="line">		desc: &#x27;请输入正确的邮箱地址!&#x27;</span><br><span class="line">	&#125;</span><br><span class="line">]</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;&lt;/style&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>子组件</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;script setup lang=<span class="string">&quot;ts&quot;</span>&gt;</span><br><span class="line"><span class="keyword">import</span> &#123; reactive, <span class="title class_">PropType</span> &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 接收父组件传进来的值</span></span><br><span class="line"><span class="keyword">const</span> props = <span class="title function_">defineProps</span>(&#123;</span><br><span class="line">	<span class="attr">rules</span>: &#123;</span><br><span class="line">		<span class="attr">type</span>: <span class="title class_">Array</span> <span class="keyword">as</span> <span class="title class_">PropType</span>&lt;<span class="title class_">RuleProps</span>[]&gt; <span class="comment">// 类型断言</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h1 id="defineEmits（子组件向父组件传值）"><a href="#defineEmits（子组件向父组件传值）" class="headerlink" title="defineEmits（子组件向父组件传值）"></a>defineEmits（子组件向父组件传值）</h1><ol>
<li><code>defineEmits</code>也是一个方法，它跟<code>defineProps</code>功能类似都是帮助了组件拿到父级传过来的物料，不过一个是属性<br><code>（props）</code>一个是事件<code>（emit）</code>；</li>
<li>动态绑定<code>props</code>是用：绑定<code>emit</code>是用<code>@</code></li>
<li>关于绑定的这个<code>@</code>符号，其实很好记忆，因为在<code>Vue</code>的<code>template</code>里，所有的事件绑定都是通过<code>@</code>，比如：<code>@click</code>、<code>@change</code>等</li>
<li>在绑定<code>emit</code>时，需要使用短横线写法与组件和<code>prop</code>一样，事件名提供了自动的大小写转换</li>
<li>例如：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;my-component @my-event=<span class="string">&quot;doSomething&quot;</span>&gt;&lt;/my-component&gt;</span><br><span class="line"><span class="variable language_">this</span>.$emit(<span class="string">&#x27;myEvent&#x27;</span>)</span><br></pre></td></tr></table></figure>
<ol>
<li>和<code>props</code>一样，也需要在<code>setup</code>的入参里引入<code>emit</code>，才允许操作</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取 emit</span></span><br><span class="line"><span class="keyword">const</span> emit = <span class="title function_">defineEmits</span>([<span class="string">&#x27;chang-name&#x27;</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">// 调用emit</span></span><br><span class="line"><span class="title function_">emit</span>(<span class="string">&#x27;chang-name&#x27;</span>,<span class="string">&#x27;老杨&#x27;</span>)</span><br></pre></td></tr></table></figure>
<ol>
<li><code>emit</code>的第二个参数开始是父组件那边要接收的自定义数据，为了开发上的便利，建议如果需要传多个数据的情况下，直接将第二个参数设置为一个对象，把所有数据都放到对象里，传递和接收起来都会方便很多。</li>
<li>实例：</li>
</ol>
<ol>
<li>父组件。自定义事件，例如：<code>@submit-from=&quot;onsubmit&quot;</code>，设置回调函数，处理方法</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;!-- 登录 --&gt;</span><br><span class="line">	&lt;div class=&quot;container mt-5&quot; style=&quot;max-width: 800px&quot;&gt;</span><br><span class="line">		&lt;ValidationFrom @submit-from=&quot;onsubmit&quot;&gt;</span><br><span class="line">			&lt;div class=&quot;mb-3&quot;&gt;</span><br><span class="line">				&lt;label for=&quot;exampleInputEmail1&quot; class=&quot;form-label&quot;&gt;Email address&lt;/label&gt;</span><br><span class="line">				&lt;ValidationInput :rules=&quot;emailRule&quot;&gt;&lt;/ValidationInput&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line">		&lt;/ValidationFrom&gt;</span><br><span class="line">	&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup lang=&quot;ts&quot;&gt;</span><br><span class="line">import ValidationFrom from &#x27;../components/ValidationFrom.vue&#x27;</span><br><span class="line"></span><br><span class="line">// 通过传参的形式，可以获取到传进来的参数</span><br><span class="line">const onsubmit = (bool: boolean) =&gt; &#123;</span><br><span class="line">	console.log(123, bool)</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;&lt;/style&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>子组件，使用defineEmits方法，并发射数据</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;!-- 登录表单提交 --&gt;</span><br><span class="line">	&lt;form&gt;</span><br><span class="line">		&lt;!-- 接收子组件传进的数据结构，使用插槽 --&gt;</span><br><span class="line">		&lt;slot name=&quot;default&quot;&gt;&lt;/slot&gt;</span><br><span class="line">		&lt;!-- 接收按钮 --&gt;</span><br><span class="line">		&lt;slot name=&quot;submit&quot;&gt;</span><br><span class="line">			&lt;!-- 按钮的默认样式 --&gt;</span><br><span class="line">			&lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; @click.prevent=&quot;submision&quot;&gt;Submit&lt;/button&gt;</span><br><span class="line">		&lt;/slot&gt;</span><br><span class="line">	&lt;/form&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup lang=&quot;ts&quot;&gt;</span><br><span class="line">const emit = defineEmits([&#x27;submit-from&#x27;])</span><br><span class="line">// 使用该事件</span><br><span class="line">const submision = () =&gt; &#123;</span><br><span class="line">	emit(&#x27;submit-from&#x27;, &#x27;false&#x27;) // 触发父组件的事件</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;&lt;/style&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="插槽的使用"><a href="#插槽的使用" class="headerlink" title="插槽的使用"></a>插槽的使用</h1><ol>
<li>父组件，使用<code>template</code>标签，标签内容就是传递给子组件的值</li>
<li>使用<code>v-slot:</code>来确定传给谁，后跟子组件<code>solt</code>标签定义的名称</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;!-- 登录 --&gt;</span><br><span class="line">	&lt;div class=&quot;container mt-5&quot; style=&quot;max-width: 800px&quot;&gt;</span><br><span class="line">		&lt;ValidationFrom&gt;</span><br><span class="line">            &lt;div class=&quot;mb-3 form-check&quot;&gt;</span><br><span class="line">				&lt;input type=&quot;checkbox&quot; class=&quot;form-check-input&quot; id=&quot;exampleCheck1&quot; /&gt;</span><br><span class="line">				&lt;label class=&quot;form-check-label&quot; for=&quot;exampleCheck1&quot;&gt;Check me out&lt;/label&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line">			&lt;!-- 涉及到一个思想：以默认配置为优先，以用户配置为覆盖</span><br><span class="line">				用户可以更改，按钮的样式，</span><br><span class="line">				将用户选择更改的按钮样式，与默认的按钮进行替换</span><br><span class="line">			--&gt;</span><br><span class="line">			&lt;template v-slot:submit&gt;</span><br><span class="line">				&lt;button type=&quot;button&quot; class=&quot;btn btn-success&quot;&gt;Success&lt;/button&gt;</span><br><span class="line">			&lt;/template&gt;</span><br><span class="line">		&lt;/ValidationFrom&gt;</span><br><span class="line">	&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup lang=&quot;ts&quot;&gt;</span><br><span class="line">import ValidationFrom from &#x27;../components/ValidationFrom.vue&#x27;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;&lt;/style&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>子组件，使用<code>slot</code>标签，并定义<code>name</code>值</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;!-- 登录表单提交 --&gt;</span><br><span class="line">	&lt;form&gt;</span><br><span class="line">		&lt;!-- 接收子组件传进的数据结构，使用插槽 --&gt;</span><br><span class="line">		&lt;slot name=&quot;default&quot;&gt;&lt;/slot&gt;</span><br><span class="line">		&lt;!-- 接收按钮 --&gt;</span><br><span class="line">		&lt;slot name=&quot;submit&quot;&gt;</span><br><span class="line">			&lt;!-- 按钮的默认样式 --&gt;</span><br><span class="line">			&lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;</span><br><span class="line">		&lt;/slot&gt;</span><br><span class="line">	&lt;/form&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup lang=&quot;ts&quot;&gt;&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;&lt;/style&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="什么是SPA"><a href="#什么是SPA" class="headerlink" title="什么是SPA"></a>什么是SPA</h1><h2 id="SPA基础介绍"><a href="#SPA基础介绍" class="headerlink" title="SPA基础介绍"></a>SPA基础介绍</h2><ol>
<li><code>SPA</code>是<code>Single Page Application</code>的缩写，指的是单页应用程序。</li>
<li>简单来讲就是只在一个页面内完成整个网站的复杂页面交互，而不刷新页面的应用。</li>
<li>听起来像不像是在描述<code>ajax</code>，确实单页面技术看起来更像是<code>ajax</code>的一种技术延伸</li>
<li>它是一种<code>Web</code>应用程序的架构模式，通过使用<code>JavaScript</code>等前端技术，将整个应用程序放在一个单独的页面中，通过动态加载数据和页面内容来实现页面的切换和交互。</li>
<li>相比于传统的多页应用程序，<code>SPA</code>具有更快的页面加载速度、更好的用户体验和更高的可维护性。</li>
<li>在<code>SPA</code>中，前端框架如<code>Vue.js</code>、<code>React</code>等扮演着重要的角色，它们提供了一系列的工具和组件，帮助开发者快速构建复杂的单页应用程序。</li>
<li>同时，<code>SPA</code>也需要注意一些问题，如<code>SEO</code>优化、路由管理、数据缓存等。</li>
</ol>
<h2 id="单应用开发优劣"><a href="#单应用开发优劣" class="headerlink" title="单应用开发优劣"></a>单应用开发优劣</h2><ol>
<li>优势<ol>
<li>无刷新体验</li>
<li>完全前端组件化</li>
<li><code>API</code>共享</li>
<li>组件共享</li>
</ol>
</li>
<li>劣势<ol>
<li>首屏加载慢（可采用，骨架屏，懒加载等来优化）</li>
<li>较高的开发门槛（前端开发人员比后端开发人员多，靠简单的三板斧是找不到工作的）</li>
<li>不利于<code>SEO</code>（可采用<code>SSR</code>等来优化）</li>
</ol>
</li>
<li></li>
</ol>
<h2 id="SPA特征"><a href="#SPA特征" class="headerlink" title="SPA特征"></a>SPA特征</h2><ol>
<li><code>SPA（Single Page Application）</code>是一种<code>Web</code>应用程序的架构模式，它通过使用JavaScript等前端技术，将整个应用程序的所有页面都加载到一个单独的<code>HTML</code>页面中，从而实现无需刷新页面即可实现页面内容的更新和交互。</li>
<li><code>SPA</code>应用程序通常使用<code>AJAX</code>技术从服务器获取数据，并使用前端框架（如<code>React</code>、<code>Angular</code>、<code>Vue</code>等）来管理应用程序的状态和路由。</li>
<li><code>SPA</code>应用程序的优点包括更快的页面加载速度、更好的用户体验和更容易的维护和扩展。</li>
<li>但是，<code>SPA</code>应用程序也存在一些缺点，如<code>SEO</code>不友好、首次加载时间较长等。</li>
</ol>
<h2 id="SPA实现原理"><a href="#SPA实现原理" class="headerlink" title="SPA实现原理"></a>SPA实现原理</h2><ol>
<li><p><code>SPA</code>实现原理主要包括以下几个方面：</p>
<ol>
<li>前端路由：<code>SPA</code>应用程序通过前端路由来实现页面的切换和更新。前端路由可以使用<code>HTML5</code>的<code>History API</code>或者<code>Hash</code>路由来实现。当用户点击页面链接或者进行其他操作时，前端路由会根据<code>URL</code>的变化来切换页面内容，而不需要重新加载整个页面。</li>
<li><code>AJAX</code>数据获取：<code>SPA</code>应用程序通过<code>AJAX</code>技术从服务器获取数据。当用户进行操作时，<code>SPA</code>应用程序会向服务器发送请求，服务器返回数据后，<code>SPA</code>应用程序会使用前端框架来更新页面内容。</li>
<li>前端框架：<code>SPA</code>应用程序通常使用前端框架来管理应用程序的状态和路由。前端框架可以帮助开发者更容易地实现页面的交互和更新。常用的前端框架包括<code>React</code>、<code>Angular</code>、<code>Vue</code>等。</li>
<li>模板引擎：<code>SPA</code>应用程序通常使用模板引擎来生成<code>HTML</code>页面。模板引擎可以帮助开发者更容易地生成页面内容，并且可以实现页面的复用。</li>
</ol>
</li>
<li><p>总的来说，<code>SPA</code>应用程序通过前端路由、<code>AJAX</code>数据获取、前端框架和模板引擎等技术来实现页面的无刷新更新和交互。这种架构模式可以提高页面加载速度和用户体验，但也需要注意一些缺点，如<code>SEO</code>不友好和首次加载时间较长等。</p>
</li>
</ol>
<h2 id="history实现原理"><a href="#history实现原理" class="headerlink" title="history实现原理"></a>history实现原理</h2><ol>
<li><p><code>HTML5</code>的<code>History API</code>是一种前端路由实现方式，它可以通过<code>JavaScript</code>来操作浏览器的历史记录，从而实现页面的切换和更新。<code>History API</code>主要包括以下几个方法：</p>
<ol>
<li><code>pushState(state, title, url)</code>：向浏览器的历史记录中添加一条新的记录，并且更新当前页面的<code>URL</code>。<code>state</code>参数可以是任意类型的数据，用于保存当前页面的状态信息。<code>title</code>参数是可选的，用于设置新记录的标题。<code>url</code>参数是新记录的<code>URL</code>。</li>
<li><code>replaceState(state, title, url)</code>：替换当前页面在浏览器历史记录中的记录，并且更新当前页面的URL。<code>state</code>、<code>title</code>和<code>url</code>参数的含义与<code>pushState</code>方法相同。</li>
<li><code>popstate</code>事件：当用户点击浏览器的前进或后退按钮时，会触发<code>popstate</code>事件。开发者可以通过监听<code>popstate</code>事件来实现页面的切换和更新。</li>
</ol>
</li>
<li><p><code>History API</code>的实现原理主要是通过改变浏览器的<code>URL</code>来实现页面的切换和更新。当用户点击页面链接或者进行其他操作时，开发者可以使用<code>pushState</code>或<code>replaceState</code>方法来添加或替换浏览器历史记录中的记录，并且更新当前页面的<code>URL</code>。当用户点击浏览器的前进或后退按钮时，浏览器会触发<code>popstate</code>事件，开发者可以通过监听<code>popstate</code>事件来获取当前页面的状态信息，并且更新页面内容。这种方式可以实现无刷新更新页面内容，提高用户体验。</p>
</li>
<li>参数：</li>
<li>pushState（）方法：状态对象、标题（目前被忽略）、可选的URL</li>
<li>具体参数可咨询：<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/API/History_API?id=">https://developer.mozilla.org/zh-CN/docs/Web/API/History_API?id=</a></li>
</ol>
<h2 id="history模式"><a href="#history模式" class="headerlink" title="history模式"></a>history模式</h2><ol>
<li><p><code>History</code>模式是<code>HTML5</code>的一种前端路由实现方式，它通过使用<code>HistoryAPI</code>来实现页面的切换和更新。与<code>Hash</code>路由不同的是，<code>History</code>模式可以使用真实的<code>URL</code>来访问页面，而不需要使用<code>URL</code>中的<code>hash</code>值。<code>History</code>模式主要包括以下几个步骤：</p>
<ol>
<li>启用<code>History</code>模式：开发者需要在服务器端配置，以便支持<code>History</code>模式。具体来说，需要将所有的<code>URL</code>请求都重定向到同一个<code>HTML</code>文件中，例如index.html。</li>
<li>监听<code>popstate</code>事件：当用户点击浏览器的前进或后退按钮时，会触发<code>popstate</code>事件。开发者可以通过监听<code>popstate</code>事件来实现页面的切换和更新。</li>
<li>改变<code>URL</code>：当用户点击页面链接或者进行其他操作时，开发者可以使用<code>pushState</code>或<code>replaceState</code>方法来改变<code>URL</code>，并且更新页面内容。</li>
<li>解析<code>URL</code>：当URL发生变化时，开发者可以通过解析URL来获取页面的状态信息，并且更新页面内容。</li>
</ol>
</li>
<li><p><code>History</code>模式的实现原理主要是通过使用真实的<code>URL</code>来实现页面的切换和更新。</p>
</li>
<li>当用户点击页面链接或者进行其他操作时，开发者可以使用<code>pushState</code>或<code>replaceState</code>方法来改变URL，并且更新页面内容。</li>
<li>当用户点击浏览器的前进或后退按钮时，浏览器会触发<code>popstate</code>事件，开发者可以通过监听<code>popstate</code>事件来获取当前页面的状态信息，并且更新页面内容。这种方式可以提高用户体验，并且对<code>SEO</code>友好。</li>
</ol>
<h2 id="Hash实现原理"><a href="#Hash实现原理" class="headerlink" title="Hash实现原理"></a>Hash实现原理</h2><ol>
<li><code>Hash</code>路由是一种前端路由实现方式，它通过改变<code>URL</code>中的<code>hash</code>值来实现页面的切换和更新。<code>Hash</code>路由主要包括以下几个步骤：<ol>
<li>监听<code>hashchange</code>事件：当<code>URL</code>中的<code>hash</code>值发生变化时，浏览器会触发<code>hashchange</code>事件。开发者可以通过监听<code>hashchange</code>事件来实现页面的切换和更新。</li>
<li>改变<code>URL</code>中的<code>hash</code>值：当用户点击页面链接或者进行其他操作时，开发者可以通过修改<code>URL</code>中的<code>hash</code>值来实现页面的切换和更新。例如，可以使用<code>location.hash</code>属性来获取或设置<code>URL</code>中的<code>hash</code>值。</li>
<li>解析<code>hash</code>值：当<code>URL</code>中的<code>hash</code>值发生变化时，开发者可以通过解析<code>hash</code>值来获取页面的状态信息，并且更新页面内容。例如，可以使用正则表达式或者字符串分割等方式来解析<code>hash</code>值。</li>
</ol>
</li>
<li><code>Hash</code>路由的实现原理主要是通过改变<code>URL</code>中的<code>hash</code>值来实现页面的切换和更新。</li>
<li>当用户点击页面链接或者进行其他操作时，开发者可以通过修改URL中的<code>hash</code>值来触发<code>hashchange</code>事件，并且更新页面内容。</li>
<li>当<code>hashchange</code>事件被触发时，开发者可以通过解析<code>hash</code>值来获取页面的状态信息，并且更新页面内容。</li>
<li>这种方式可以实现无刷新更新页面内容，提高用户体验。</li>
<li>但是，由于<code>URL</code>中的<code>hash</code>值不会被搜索引擎爬虫解析，因此<code>Hash</code>路由对<code>SEO</code>不友好。</li>
<li>在JavaScript中：</li>
<li>可通过<code>location.hash</code>来访问<code>hash</code></li>
<li>如果值发生改变，会触发<code>HashChang</code>这个事件</li>
</ol>
<h1 id="Vuex"><a href="#Vuex" class="headerlink" title="Vuex"></a>Vuex</h1><ol>
<li>在<code>vuex</code>中如果要保证<code>store</code>数据的响应性，就要使用<code>vue</code>中的计算属性<code>computed</code></li>
<li>通过<code>useStore</code>来访问<code>store</code>中的数据</li>
<li>如果要触发<code>sotre</code>中的事件方法，可以使用<code>commit(&#39;事件名&#39;,参数)</code></li>
<li>实例：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;script setup lang=<span class="string">&quot;ts&quot;</span>&gt;</span><br><span class="line"><span class="keyword">import</span> &#123; useStore &#125; <span class="keyword">from</span> <span class="string">&#x27;vuex&#x27;</span></span><br><span class="line"><span class="keyword">import</span> &#123; computed &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> store = <span class="title function_">useStore</span>()</span><br><span class="line"><span class="keyword">const</span> <span class="title class_">ColumnDataList</span> = <span class="title function_">computed</span>(<span class="function">() =&gt;</span> store.<span class="property">state</span>.<span class="property">ColumnData</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">ColumnDataList</span>)</span><br><span class="line">store.<span class="title function_">commit</span>(<span class="string">&#x27;increment&#x27;</span>) <span class="comment">// 触发store中的事件函数，(&#x27;事件名&#x27;,参数)</span></span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h2 id="触发的方法"><a href="#触发的方法" class="headerlink" title="触发的方法"></a>触发的方法</h2><ol>
<li>注意：<code>axios</code>的触发方式和<code>methods</code>的触发方式不一样</li>
<li>axios的触发方式：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">store.<span class="title function_">dispatch</span>(<span class="string">&#x27;requireColumns&#x27;</span>) <span class="comment">// 获取专栏数据，触发action中的方法</span></span><br></pre></td></tr></table></figure>
<ol>
<li>方法的触发方式：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">store.<span class="title function_">commit</span>(<span class="string">&#x27;login&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="导航守卫"><a href="#导航守卫" class="headerlink" title="导航守卫"></a>导航守卫</h1><ol>
<li>通俗的理解：<ol>
<li>开始是pending状态,也就是等待</li>
<li>to: 要去的地方</li>
<li>from：离开的地方</li>
<li>next：下一步</li>
<li>fufilled成功的状态</li>
</ol>
</li>
<li>具体看官网：<a target="_blank" rel="noopener" href="https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#%E5%85%A8%E5%B1%80%E5%89%8D%E7%BD%AE%E5%AE%88%E5%8D%AB">https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#%E5%85%A8%E5%B1%80%E5%89%8D%E7%BD%AE%E5%AE%88%E5%8D%AB</a></li>
<li>实例：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">router.<span class="title function_">beforeEach</span>(<span class="function">(<span class="params">to, <span class="keyword">from</span>, next</span>) =&gt;</span> &#123;</span><br><span class="line">	<span class="comment">// console.log(&#x27;to&#x27;, to)</span></span><br><span class="line">	<span class="comment">// console.log(&#x27;from&#x27;, from)</span></span><br><span class="line">	<span class="comment">// console.log(&#x27;next&#x27;, next)</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// 如果路由不为login，并且isLogin为false，就跳转到login</span></span><br><span class="line">	<span class="keyword">if</span> (to.<span class="property">name</span> !== <span class="string">&#x27;login&#x27;</span> &amp;&amp; !store.<span class="property">state</span>.<span class="property">user</span>.<span class="property">isLogin</span>) &#123;</span><br><span class="line">		<span class="title function_">next</span>(&#123; <span class="attr">name</span>: <span class="string">&#x27;login&#x27;</span> &#125;) <span class="comment">//路由重定向</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="title function_">next</span>() <span class="comment">// 下一步，放行</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="路由元信息"><a href="#路由元信息" class="headerlink" title="路由元信息"></a>路由元信息</h1><ol>
<li>具体看官网：<a target="_blank" rel="noopener" href="https://router.vuejs.org/zh/guide/advanced/meta.html">https://router.vuejs.org/zh/guide/advanced/meta.html</a></li>
<li>有时，你可能希望将任意信息附加到路由上，如过渡名称、谁可以访问路由等。这些事情可以通过接收属性对象的<code>meta</code>属性来实现，并且它可以在路由地址和导航守卫上都被访问到。定义路由的时候你可以这样配置 <code>meta</code> 字段：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> routes = [</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="attr">path</span>: <span class="string">&#x27;/posts&#x27;</span>,</span><br><span class="line">    <span class="attr">component</span>: <span class="title class_">PostsLayout</span>,</span><br><span class="line">    <span class="attr">children</span>: [</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">path</span>: <span class="string">&#x27;new&#x27;</span>,</span><br><span class="line">        <span class="attr">component</span>: <span class="title class_">PostsNew</span>,</span><br><span class="line">        <span class="comment">// 只有经过身份验证的用户才能创建帖子</span></span><br><span class="line">        <span class="attr">meta</span>: &#123; <span class="attr">requiresAuth</span>: <span class="literal">true</span> &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">path</span>: <span class="string">&#x27;:id&#x27;</span>,</span><br><span class="line">        <span class="attr">component</span>: <span class="title class_">PostsDetail</span></span><br><span class="line">        <span class="comment">// 任何人都可以阅读文章</span></span><br><span class="line">        <span class="attr">meta</span>: &#123; <span class="attr">requiresAuth</span>: <span class="literal">false</span> &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<ol>
<li>其中<code>requiresAuth: true</code>：是为当前路由做验证的</li>
</ol>
<h1 id="路由元信息、导航守卫总结"><a href="#路由元信息、导航守卫总结" class="headerlink" title="路由元信息、导航守卫总结"></a>路由元信息、导航守卫总结</h1><ol>
<li>如果想用户没登录，也可以查看部分内容，可使用路由元信息，搭配导航守卫来使用</li>
<li>实例：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; createRouter, createWebHashHistory &#125; <span class="keyword">from</span> <span class="string">&#x27;vue-router&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">Home</span> <span class="keyword">from</span> <span class="string">&#x27;../views/Home.vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">Login</span> <span class="keyword">from</span> <span class="string">&#x27;../views/Login.vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> columnDetail <span class="keyword">from</span> <span class="string">&#x27;../components/columnDetail.vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">CreateArticle</span> <span class="keyword">from</span> <span class="string">&#x27;../components/CreateArticle.vue&#x27;</span></span><br><span class="line"><span class="keyword">import</span> store <span class="keyword">from</span> <span class="string">&#x27;../store/store&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 路由注册表</span></span><br><span class="line"><span class="keyword">const</span> routes = [</span><br><span class="line">	&#123; <span class="attr">path</span>: <span class="string">&#x27;/&#x27;</span>, <span class="attr">name</span>: <span class="string">&#x27;home&#x27;</span>, <span class="attr">component</span>: <span class="title class_">Home</span> &#125;,</span><br><span class="line">	&#123; <span class="attr">path</span>: <span class="string">&#x27;/login&#x27;</span>, <span class="attr">name</span>: <span class="string">&#x27;login&#x27;</span>, <span class="attr">component</span>: <span class="title class_">Login</span>，<span class="attr">meta</span>: &#123; <span class="attr">requiresAuthLogin</span>: <span class="literal">true</span> &#125; &#125;,</span><br><span class="line">	&#123; <span class="attr">path</span>: <span class="string">&#x27;/column:id&#x27;</span>, <span class="attr">name</span>: <span class="string">&#x27;column&#x27;</span>, <span class="attr">component</span>: columnDetail &#125;,</span><br><span class="line">	&#123; <span class="attr">path</span>: <span class="string">&#x27;/creatre&#x27;</span>, <span class="attr">name</span>: <span class="string">&#x27;creatre&#x27;</span>, <span class="attr">component</span>: <span class="title class_">CreateArticle</span>, <span class="attr">meta</span>: &#123; <span class="attr">requiresAuth</span>: <span class="literal">true</span> &#125; &#125;<span class="comment">// 需要做验证</span></span><br><span class="line">]</span><br><span class="line"><span class="comment">// 使用router</span></span><br><span class="line"><span class="keyword">const</span> router = <span class="title function_">createRouter</span>(&#123;</span><br><span class="line">	routes, <span class="comment">//路由注册表</span></span><br><span class="line">	<span class="attr">history</span>: <span class="title function_">createWebHashHistory</span>() <span class="comment">// 表示要采取哪一种模式，history、hash，使用hash加history的模式</span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">//导航守卫</span></span><br><span class="line">router.<span class="title function_">beforeEach</span>(<span class="function">(<span class="params">to, <span class="keyword">from</span>, next</span>) =&gt;</span> &#123;</span><br><span class="line">	<span class="comment">// 如果路由不为login，并且isLogin为false，就跳转到login</span></span><br><span class="line">	<span class="comment">// 查看路由是否要做验证，如果要要做验证且没有登录，就跳转到登录页面</span></span><br><span class="line">    <span class="comment">// requiresAuth 如果为 true，就做验证</span></span><br><span class="line">	<span class="keyword">if</span> (to.<span class="property">meta</span>.<span class="property">requiresAuth</span> &amp;&amp; !store.<span class="property">state</span>.<span class="property">user</span>.<span class="property">isLogin</span>) &#123;</span><br><span class="line">		<span class="title function_">next</span>(&#123; <span class="attr">name</span>: <span class="string">&#x27;login&#x27;</span> &#125;) <span class="comment">//路由重定向</span></span><br><span class="line">	&#125; <span class="keyword">else</span> <span class="keyword">if</span> (to.<span class="property">meta</span>.<span class="property">requiresAuthLogin</span> &amp;&amp; store.<span class="property">state</span>.<span class="property">user</span>.<span class="property">isLogin</span>) &#123;</span><br><span class="line">		<span class="comment">// 表示登录后，不在跳转到登录页面</span></span><br><span class="line">		<span class="title function_">next</span>(&#123; <span class="attr">name</span>: <span class="string">&#x27;/&#x27;</span> &#125;) <span class="comment">//路由重定向</span></span><br><span class="line">	&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">		<span class="title function_">next</span>() <span class="comment">// 下一步，放行</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> router</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="JWT运行机制"><a href="#JWT运行机制" class="headerlink" title="JWT运行机制"></a>JWT运行机制</h1><ol>
<li>JWT官网：<a target="_blank" rel="noopener" href="https://jwt.io/#debugger-io">https://jwt.io/#debugger-io</a></li>
<li><code>JWT（JSON Web Token）</code>是一种轻量级的身份验证和授权机制，它是通过在用户和服务器之间传递<code>JSON</code>对象来实现的。</li>
<li>是一种用于身份验证和授权的开放标准。它是在网络应用之间安全传输信息的一种方式。<code>JWT</code>由三部分组成：头部、载荷和签名。</li>
<li>JWT：基于session的身份认证，基于Token的认证两种认证方案。</li>
<li><code>JWT</code>的运行流程如下：<ol>
<li>用户使用用户名和密码向服务器发起登录请求。</li>
<li>服务器验证用户身份，并生成一个<code>JWT</code>。</li>
<li>服务器将<code>JWT</code>返回给客户端。</li>
<li>客户端将<code>JWT</code>保存在本地存储中（如<code>localStorage</code>或<code>sessionStorage</code>）。</li>
<li>客户端在每次向服务器发起请求时，将<code>JWT</code>作为请求头的<code>Authorization</code>字段的值发送给服务器。</li>
<li>服务器接收到请求后，会验证<code>JWT</code>的合法性，并从<code>JWT</code>中解析出用户信息。</li>
<li>如果<code>JWT</code>验证通过，服务器将返回请求的资源。</li>
<li>如果<code>JWT</code>验证不通过，服务器将返回<code>401 Unauthorized</code>错误。</li>
</ol>
</li>
<li><code>JWT</code>的运行机制中，客户端不需要在服务器上保存任何会话信息，服务器也不需要在其本地存储中保存任何会话信息，这使得<code>JWT</code>适合于分布式系统和微服务架构。同时，<code>JWT</code>还具有可扩展性和安全性等优点。</li>
<li>总之，<code>JWT</code>的运行机制是通过在客户端和服务器之间传递加密的<code>JSON</code>数据来实现身份验证和授权。它具有简单、安全、可扩展等优点，被广泛应用于<code>Web</code>应用程序和<code>API</code>的身份验证和授权。</li>
<li>基于Token认证：</li>
<li>总结：一共分四步</li>
<li>创建Token：<ol>
<li>在用户进行身份验证之后，服务器会生成一个<code>JWT</code>，并将其作为响应的一部分返回给客户端。</li>
<li><code>JWT</code>通常包含一些标准的声明（如<code>令牌</code>的过期时间）和自定义的声明（如用户的ID）。</li>
<li>这些声明被编码为<code>JSON</code>格式，并使用<code>Base64</code>编码进行编码。</li>
</ol>
</li>
<li>传输<code>Token</code>：<ol>
<li>客户端在收到<code>JWT</code>后，将其存储在本地（通常是在浏览器的<code>本地存储</code>或<code>会话存储</code>中）。</li>
<li>然后，在每个后续的请求中，客户端都会将<code>JWT</code>包含在请求的头部或请求参数中，以便将其发送给服务器。</li>
</ol>
</li>
<li>验证Token：<ol>
<li>服务器在收到<code>JWT</code>后，会对其进行验证以确保其完整性和有效性。</li>
<li>验证包括检查签名是否有效、令牌是否过期以及是否包含必需的声明等。</li>
<li>服务器可以使用之前在生成JWT时使用的密钥来验证签名。</li>
</ol>
</li>
<li>处理请求：<ol>
<li>一旦服务器验证了<code>JWT</code>并确定其有效性，它会使用其中的信息来处理请求。</li>
<li>服务器可以通过解码<code>JWT</code>中的声明来获得有关用户身份和访问权限的信息。</li>
<li>这样，服务器就可以根据<code>JWT</code>中的信息对请求进行授权处理。</li>
</ol>
</li>
</ol>
<h1 id="将token存储到请求头中"><a href="#将token存储到请求头中" class="headerlink" title="将token存储到请求头中"></a>将token存储到请求头中</h1><ol>
<li>固定格式。将token存储到请求头中</li>
<li>一般写在登录的方法里面</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 固定格式。将token存储到请求头中</span></span><br><span class="line">axios.<span class="property">defaults</span>.<span class="property">headers</span>.<span class="property">common</span>[<span class="string">&#x27;Authorization&#x27;</span>] = <span class="string">`Bearer <span class="subst">$&#123;state.token&#125;</span>`</span></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">晚夜微雨问海棠</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/posts/5d3e0e97.html">http://example.com/posts/5d3e0e97.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">晚夜微雨问海棠のBlog</a>！</span></div></div><div class="tag_share"><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://s1.ax1x.com/2022/11/15/zE9P7d.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/15/zE9P7d.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://s1.ax1x.com/2022/11/15/zE9ung.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/15/zE9ung.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/f10f5b87.html" title="Chrome浏览器"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/13/zFR3xe.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-13</div><div class="title">Chrome浏览器</div></div></a></div><div><a href="/posts/4f47bf3c.html" title="JS小技巧"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtlrL9.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-19</div><div class="title">JS小技巧</div></div></a></div><div><a href="/posts/f1f3f3e5.html" title="Git 的基本使用"><img class="cover" src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fblog-file.uiaoin.com%2Fp%2F98f2c59a19d96e9f4a03257f0d348510.gif&refer=http%3A%2F%2Fblog-file.uiaoin.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1664439668&t=bbbd0da3362e971917925cc3c9f77335" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-14</div><div class="title">Git 的基本使用</div></div></a></div><div><a href="/posts/fc49771e.html" title="vue3-将axios等方法绑定到原型上供全局使用"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2023/01/27/pSNzvXF.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-27</div><div class="title">vue3-将axios等方法绑定到原型上供全局使用</div></div></a></div><div><a href="/posts/d2b9e5fd.html" title="less-loader版本问题"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2023/01/27/pSUS49x.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-27</div><div class="title">less-loader版本问题</div></div></a></div><div><a href="/posts/82edc045.html" title="node下cors跨域问题"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2023/01/27/pSUdYMn.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-27</div><div class="title">node下cors跨域问题</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#defineProps%EF%BC%88%E7%88%B6%E7%BB%84%E4%BB%B6%E5%90%91%E5%AD%90%E7%BB%84%E4%BB%B6%E4%BC%A0%E5%80%BC%EF%BC%89"><span class="toc-number">1.</span> <span class="toc-text">defineProps（父组件向子组件传值）</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#defineEmits%EF%BC%88%E5%AD%90%E7%BB%84%E4%BB%B6%E5%90%91%E7%88%B6%E7%BB%84%E4%BB%B6%E4%BC%A0%E5%80%BC%EF%BC%89"><span class="toc-number">2.</span> <span class="toc-text">defineEmits（子组件向父组件传值）</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8F%92%E6%A7%BD%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">3.</span> <span class="toc-text">插槽的使用</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFSPA"><span class="toc-number">4.</span> <span class="toc-text">什么是SPA</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#SPA%E5%9F%BA%E7%A1%80%E4%BB%8B%E7%BB%8D"><span class="toc-number">4.1.</span> <span class="toc-text">SPA基础介绍</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%95%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91%E4%BC%98%E5%8A%A3"><span class="toc-number">4.2.</span> <span class="toc-text">单应用开发优劣</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SPA%E7%89%B9%E5%BE%81"><span class="toc-number">4.3.</span> <span class="toc-text">SPA特征</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SPA%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86"><span class="toc-number">4.4.</span> <span class="toc-text">SPA实现原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#history%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86"><span class="toc-number">4.5.</span> <span class="toc-text">history实现原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#history%E6%A8%A1%E5%BC%8F"><span class="toc-number">4.6.</span> <span class="toc-text">history模式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Hash%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86"><span class="toc-number">4.7.</span> <span class="toc-text">Hash实现原理</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vuex"><span class="toc-number">5.</span> <span class="toc-text">Vuex</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A6%E5%8F%91%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">5.1.</span> <span class="toc-text">触发的方法</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AF%BC%E8%88%AA%E5%AE%88%E5%8D%AB"><span class="toc-number">6.</span> <span class="toc-text">导航守卫</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%B7%AF%E7%94%B1%E5%85%83%E4%BF%A1%E6%81%AF"><span class="toc-number">7.</span> <span class="toc-text">路由元信息</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%B7%AF%E7%94%B1%E5%85%83%E4%BF%A1%E6%81%AF%E3%80%81%E5%AF%BC%E8%88%AA%E5%AE%88%E5%8D%AB%E6%80%BB%E7%BB%93"><span class="toc-number">8.</span> <span class="toc-text">路由元信息、导航守卫总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#JWT%E8%BF%90%E8%A1%8C%E6%9C%BA%E5%88%B6"><span class="toc-number">9.</span> <span class="toc-text">JWT运行机制</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B0%86token%E5%AD%98%E5%82%A8%E5%88%B0%E8%AF%B7%E6%B1%82%E5%A4%B4%E4%B8%AD"><span class="toc-number">10.</span> <span class="toc-text">将token存储到请求头中</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://s1.ax1x.com/2023/06/24/pCtlcIx.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By 晚夜微雨问海棠</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章归档</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><div class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简切换</span></div><div class="rightMenu-item" id="menu-darkmode"><i class="fa-solid fa-moon"></i><span>切换模式</span></div></div></div><div id="rightmenu-mask"></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '',
      appKey: '',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><div class="aplayer no-destroy" data-id="7625372994" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div> <script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script> <script src="/swiper/swiper.min.js"></script> <script src="/swiper/swiperindex.js"></script> <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script> <script src="/js/title.js"></script> <script defer data-pjax src="/js/cat.js"></script> <script defer data-pjax src="/js/rightMenu.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show","#web_bg",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function history_calendar_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div>';
                console.log('已挂载history_calendar')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='/'|| '/' ==='all')){

            history_calendar_injector_config()
        } </script><script data-pjax  src="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.js"></script><script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script><script data-pjax>
    function butterfly_categories_card_injector_config(){
      var parent_div_git = document.getElementById('recent-posts');
      var item_html = '<style>li.categoryBar-list-item{width:24%;}.categoryBar-list{max-height: 190px;overflow:auto;}.categoryBar-list::-webkit-scrollbar{width:0!important}@media screen and (max-width: 650px){.categoryBar-list{max-height: 160px;}}</style><div class="recent-post-item" style="height:auto;width:100%;padding:0px;"><div id="categoryBar"><ul class="categoryBar-list"><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpicnew6.photophoto.cn%2F20120106%2Fhaimianbaobaotupian-10036689_1.jpg&amp;refer=http%3A%2F%2Fpicnew6.photophoto.cn&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648815&amp;t=a3deb15ddd7a38597964c3a05e519bd7);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Asp-Net/&quot;);" href="javascript:void(0);">Asp.Net</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://npm.elemecdn.com/anzhiyu-blog@1.1.6/img/post/common/site-backgound.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/C-系列/&quot;);" href="javascript:void(0);">C#系列</a><span class="categoryBar-list-count">8</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13012860773%2F1000.jpg&amp;refer=http%3A%2F%2Finews.gtimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648865&amp;t=1d2f13b52a7e279e8801545f59eda4e7);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Hexo重装记录/&quot;);" href="javascript:void(0);">Hexo重装记录</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202011%2F07%2F20201107183300_ac0c5.thumb.1000_0.jpeg&amp;refer=http%3A%2F%2Fc-ssl.duitang.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648887&amp;t=3d32c6b12a4cf12e5cec3585b79c1fc3);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/EF/&quot;);" href="javascript:void(0);">EF</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2F25%2Feb%2F1f%2F25eb1fd40b5a740c2b79e33f700806e5.jpg&amp;refer=http%3A%2F%2Fup.enterdesk.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648908&amp;t=6425ee3bd166b0f5c5ffa6fb18b6937b);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/LOL/&quot;);" href="javascript:void(0);">LOL</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2Ftx26%2F36080017392073.jpg&amp;refer=http%3A%2F%2Flmg.jj20.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665650136&amp;t=5cc414d0ee58c9e285218d92f6a95513);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/idea/&quot;);" href="javascript:void(0);">idea</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn10%2F320%2Fw700h420%2F20180907%2F5116-hitesuz6599636.jpg&amp;refer=http%3A%2F%2Fn.sinaimg.cn&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665650004&amp;t=6a304aa9cc7435ec1d148b8f99092bc0);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/世界/&quot;);" href="javascript:void(0);">世界</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxCi6.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/世界见闻录/&quot;);" href="javascript:void(0);">世界见闻录</a><span class="categoryBar-list-count">8</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxFzD.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/前端体系/&quot;);" href="javascript:void(0);">前端体系</a><span class="categoryBar-list-count">19</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxnot.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/副业/&quot;);" href="javascript:void(0);">副业</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxMJf.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/文案/&quot;);" href="javascript:void(0);">文案</a><span class="categoryBar-list-count">6</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxQW8.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/办公日常/&quot;);" href="javascript:void(0);">办公日常</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAx3Qg.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/朝花夕拾/&quot;);" href="javascript:void(0);">朝花夕拾</a><span class="categoryBar-list-count">12</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxYes.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/前端/&quot;);" href="javascript:void(0);">前端</a><span class="categoryBar-list-count">20</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/杂七杂八/&quot;);" href="javascript:void(0);">杂七杂八</a><span class="categoryBar-list-count">7</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/简书/&quot;);" href="javascript:void(0);">简书</a><span class="categoryBar-list-count">5</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/游戏/&quot;);" href="javascript:void(0);">游戏</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li></ul></div></div>';
      console.log('已挂载butterfly_categories_card')
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
      }
    if( document.getElementById('recent-posts') && (location.pathname ==='/'|| '/' ==='all')){
    butterfly_categories_card_injector_config()
    }
  </script><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src= "" data-lazy-src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var qweather_key = '41ea442da35546559913a6a5d54163b2';
  var gaud_map_key = '6b62fbebf584b9a22a85bfccbf90335e';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '114.35,34.79';
  var clock_default_rectangle_enable = 'true';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" data-title="博客框架为Hexo_v5.4.0" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" data-title="主题版本Butterfly_v4.2.2" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://www.jsdelivr.com/" style="margin-inline:5px" data-title="本站使用JsDelivr为静态资源提供CDN加速" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&amp;logo=jsDelivr" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" data-title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></p>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="/js/runtime/runtime.min.js"></script><script data-pjax>
  function butterfly_swiper_injector_config(){
    var parent_div_git = document.getElementById('recent-posts');
    var item_html = '<div class="recent-post-item swiper_container_card" style="height: auto;width: 100%"><div id="random"><div id="random-banner"><canvas id="peoplecanvas"></canvas></div><a id="random-hover" style="width:100%;height:auto;" href="javascript:toRandomPost()" rel="external nofollow noreferrer" one-link-mark="yes"><i class="fa fa-paper-plane" style="margin-left:10px"></i><div style="margin-left:10px">随便逛逛<i class="fa-solid fa-arrow-right" style="margin-left:10px"></i></div></a></div><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://img2.baidu.com/it/u=4087346614,241521689&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=500&amp;h=333" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-19</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt="">学生人到职业人_心态篇</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/04/xLiBTA.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-11-04</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt="">生活の奇思妙想☞2022</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/21/xcAQDH.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-11-12</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt="">少年自负凌云笔</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJbF0.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-13</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt="">租房有感</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJLWT.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-25</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt="">谷歌收藏</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJJd1.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-13</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt="">阳光不燥、微风正好</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载butterfly_swiper')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'undefined'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_swiper_injector_config();
  }
  else if (epage === cpage){
    butterfly_swiper_injector_config();
  }
  </script><script defer src="https://npm.elemecdn.com/anzhiyu-blog@1.1.6/js/swiper.min.js"></script><script defer data-pjax src="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiper_init.js"></script><script data-pjax src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/gsap/3.9.1/gsap.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/people.min.js"></script><script async src="/anzhiyu/random.js"></script><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1.5s');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '30');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('flink-list-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__flipInY');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('flink-list-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__animated');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('article-sort-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__slideInRight');
    arr[i].setAttribute('data-wow-duration', '1.5s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('site-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__flipInY');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('site-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__animated');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/wow_init.js"></script><script async src="/js/ali_font.js"></script><!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/"});</script></body></html>